package com.msos.dao.prepaidRecharge;

import com.msos.model.ReCharge.ReCharge;
import com.msos.model.customer.Customer;
import com.msos.utils.DBUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * 弟中弟：小邦
 */
public class PrepaidRechargeDao {

    QueryRunner queryRunner = new QueryRunner(DBUtils.getDs());

    //根据手机号查询用户信息
    public Customer getCustomerByPhone(String phone) throws SQLException {
        return queryRunner.query("select * from customer where phone=?",new BeanHandler<>(Customer.class),phone);
    }

    //根据卡号查询充值卡信息
    public ReCharge getRechargeByCardNumber(String cardNumber) throws SQLException {
        return queryRunner.query("select * from recharge where cardNumber=?",new BeanHandler<>(ReCharge.class),cardNumber);
    }

    //根据用户手机号进行话费充值
    public Integer AddMoneyByPhone(Double money,String phone) throws SQLException {
        return queryRunner.update(DBUtils.getCon(),"update customer set balance=balance+? where phone=?",money,phone);
    }

    //修改充值卡状态
    public Integer updateCardByNumber(Byte enabled,String cardNumber) throws SQLException {
        return queryRunner.update(DBUtils.getCon(),"update recharge set enabled=? where cardNumber=?",enabled,cardNumber);
    }
}
